home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / include / handle.h < prev    next >
C/C++ Source or Header  |  1993-09-14  |  4KB  |  127 lines

  1. /* Copyright (c) 1992 The Geometry Center; University of Minnesota
  2.    1300 South Second Street;  Minneapolis, MN  55454, USA;
  3.    
  4. This file is part of geomview/OOGL. geomview/OOGL is free software;
  5. you can redistribute it and/or modify it only under the terms given in
  6. the file COPYING, which you should have received along with this file.
  7. This and other related software may be obtained via anonymous ftp from
  8. geom.umn.edu; email: software@geom.umn.edu. */
  9.  
  10. /* Authors: Charlie Gunn, Stuart Levy, Tamara Munzner, Mark Phillips */
  11.  
  12. #ifndef _HANDLE_
  13. #define _HANDLE_
  14. /*
  15.  * Communications -- Public definitions for Handle package.
  16.  */
  17.  
  18. #include "ooglutil.h"
  19. #include "reference.h"
  20.  
  21.  
  22. typedef struct Handle    Handle;
  23. typedef struct Pool    Pool;
  24.  
  25.  
  26.  
  27.  
  28. int     HandleSetObject( Handle *, Ref *object );
  29. Ref    *HandleObject( Handle * );
  30. void     HandlePDelete(Handle **hp);
  31. char    *HandleName( Handle * );
  32. void     HandleDelete( Handle * );
  33. Pool    *HandlePool( Handle * );
  34.  
  35. #define    IO_HANDLES    1
  36. #define    IO_COMPLETE    2        
  37.  
  38. int     HandleExport( Handle *, Pool * ); /* Export */
  39. int     HandleUnExport( Handle * );    /* Cancel exported object if possible */
  40. int     HandleImport( Handle * );    /* Import now (possibly blocking) */
  41.  
  42. Handle *PoolIn(Pool *p);
  43. int     PoolOutMode( int poflags );    /* Returns old IO mode */
  44.  
  45.  
  46.     /*
  47.      * Data-specific operations for (stream-type) Pools (files, pipes).
  48.      */
  49. typedef struct HandleOps {
  50.     char *prefix;            /* Prefix for unique external naming */
  51.     int (*strmin) P((Pool *, Handle **, Ref **)); /* Read from stream */
  52.     int (*strmout) P((Pool *, Handle *, Ref *));    /* Write */
  53.     void (*Delete) P((Ref *));        /* Delete object */
  54.     int    (*resync) P((Pool *));        /* Resync pool on import err */
  55.     int    (*close) P((Pool *));        /* Close pool */
  56. } HandleOps;
  57.  
  58.     /*
  59.      * Given a string using the reference syntax,
  60.      * e.g. ``name:file'' or ``name:'',
  61.      * do whatever's necessary to create and return a handle to it.
  62.      * Might entail a lookup of an existing handle,
  63.      * or opening and possibly reading a file (as a stream-type Pool).
  64.      */
  65. extern Handle *HandleReferringTo(int prefixch, char *str, HandleOps *ops, Handle **hp);
  66.  
  67.  
  68.     /*
  69.       * Given a Handle's name and type (as given by HandleOps),
  70.      * return it or NULL if it doesn't exist.
  71.      */
  72. extern Handle *HandleByName( char *, HandleOps * );
  73.  
  74.     /*
  75.      * If a Handle with this name already exists, return it;
  76.      * otherwise, create a new one with NULL value.
  77.      */
  78. extern Handle *HandleCreate( char *name, HandleOps *ops );
  79.  
  80.     /*
  81.      * Set a Handle's object to obj, creating the Handle if necessary.
  82.      * Update all registered references to the Handle's value.
  83.      * Return the (possibly new) Handle.
  84.      */
  85. extern Handle *HandleAssign( char *name, HandleOps *ops, Ref *obj );
  86.  
  87.     /*
  88.      * Register a reference to a Handle's value.
  89.      * Whenever the value changes, a call is made to:
  90.      *    (*update)(Handle **hp, Ref *parentobject, void *info)
  91.      * It's intended that "info" will be a key used by the update
  92.      * procedure to know which reference to update.
  93.      * The update procedure is automatically called once when
  94.      * registration is done.
  95.      */
  96. extern int HandleRegister( Handle **hp, Ref *parent, void *info, void (*update)());
  97.  
  98.     /*
  99.      * Unregister (all callbacks on) a reference to a Handle's value.
  100.      * It's important to do this when deleting an object,
  101.      * lest dangling pointers cause trouble.
  102.      * It's harmless to remove a reference which was never registered.
  103.      */
  104. extern void HandleUnregister(Handle **hp);
  105.  
  106.     /* Unregister just one callback on a reference to a Handle's value.
  107.      * HandleUnregister() is the one to use when deleting an object.
  108.      * The viewer needs this to keep track of callbacks it plants
  109.      * throughout Geom trees, which trigger e.g. BBox recomputation.
  110.      */
  111. extern void HandleUnregisterJust(Handle **hp, Ref *par, void *info, void (*upd)());
  112.  
  113.     /*
  114.      * Unregister all callbacks matching a given pattern, no matter
  115.      * which Handle they're associated with.  Another routine needed
  116.      * for the viewer, called whenever a Geom tree is replaced.
  117.      */
  118. extern void HandleUnregisterAll(Ref *par, void *info, void (*upd)());
  119.  
  120.     /*
  121.      * Suitable update() func for HandleRegister in many cases.
  122.      * Just deletes *objp then assigns *objp = (*hp)->object when called.
  123.      */
  124. extern void HandleUpdRef(Handle **hp, Ref *parent, Ref **objp);
  125.  
  126. #endif /*_HANDLE_*/
  127.